// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MarketQuote.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge
{
    #region Usings

    using System;

    using Org.OpenTrader.Framework.Forge.Enums;
    using Org.OpenTrader.Framework.Forge.Interfaces;

    #endregion

    /// <summary>
    /// The market quote update.
    /// </summary>
    [Serializable]
    public class MarketQuote
    {
        #region Properties

        /// <summary>
        /// Gets a value indicating whether Closed.
        /// </summary>
        public bool Closed { get; private set; }

        /// <summary>
        /// Gets Contribution.
        /// </summary>
        public IContribution Contribution { get; private set; }

        /// <summary>
        /// Gets a value indicating whether HasValue.
        /// </summary>
        public bool HasValue { get; private set; }

        /// <summary>
        /// Gets or sets Price.
        /// </summary>
        public double Price { get; private set; }

        /// <summary>
        /// Gets QuoteKey.
        /// </summary>
        public string QuoteKey { get; private set; }

        /// <summary>
        /// Gets or sets Side.
        /// </summary>
        public ESide Side { get; private set; }

        /// <summary>
        /// Gets or sets Size.
        /// </summary>
        public int Size { get; private set; }

        /// <summary>
        /// Gets or sets Stamp.
        /// </summary>
        public DateTime Stamp { get; private set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// The closing quote.
        /// </summary>
        /// <param name="quoteKey">
        /// The quote key.
        /// </param>
        /// <param name="stamp">
        /// The stamp.
        /// </param>
        /// <param name="side">
        /// The side.
        /// </param>
        /// <returns>
        /// </returns>
        public static MarketQuote ClosingQuote(string quoteKey, DateTime stamp, ESide side)
        {
            var upd = new MarketQuote { QuoteKey = quoteKey, Closed = true, Side = side, Stamp = stamp };
            upd.HasValue = true;
            return upd;
        }

        /// <summary>
        /// The quote.
        /// </summary>
        /// <param name="quoteKey">
        /// The quote key.
        /// </param>
        /// <param name="stamp">
        /// The stamp.
        /// </param>
        /// <param name="side">
        /// The side.
        /// </param>
        /// <param name="price">
        /// The price.
        /// </param>
        /// <param name="size">
        /// The size.
        /// </param>
        /// <param name="contribution">
        /// The contribution.
        /// </param>
        /// <returns>
        /// </returns>
        public static MarketQuote Quote(string quoteKey, DateTime stamp, ESide side, double price, int size, IContribution contribution)
        {
            var upd = new MarketQuote { QuoteKey = quoteKey, Stamp = stamp, Side = side, Size = size, Price = price, Contribution = contribution };
            upd.HasValue = true;
            return upd;
        }

        /// <summary>
        /// The to string.
        /// </summary>
        /// <returns>
        /// The to string.
        /// </returns>
        public override string ToString()
        {
            if (!this.Closed)
            {
                return string.Format("MarketQuote: QuotedId={0};Side={1};Price={2};Size={3}", this.QuoteKey, this.Side, this.Price, this.Size);
            }

            return string.Format("MarketQuote: QuotedId={0};Closed", this.QuoteKey);
        }

        #endregion
    }
}